<template>
	<view class="container" v-if="loaded">
		<view class="row">
			<view class="levelup">
				<text>预计赚 {{commission_gift_card_share}} 礼品券</text>
			</view>
		</view>
		
		<view class="h1">
			<text>{{title}}</text>
		</view>
		
		<view class="tips">
			<text>选择需要分享的图片</text>
		</view>
		
		<view class="photos">
			<view class="item">
				<image :src="sharePic" mode="widthFix" class="pic" @click="onPhotosClick(0)"></image>
				
				<view class="btn" @click="onPhotosSelectClick(0)">
					<image v-show="currentPic == 0" src="../../../static/fanli/icon_selected.png" mode="" class="icon"></image>
				</view>
			</view>
			
			<view class="item">
				<image :src="sharePic2" mode="widthFix" class="pic" @click="onPhotosClick(1)"></image>
				
				<view class="btn" @click="onPhotosSelectClick(1)">
					<image v-show="currentPic == 1" src="../../../static/fanli/icon_selected.png" mode="" class="icon"></image>
				</view>
			</view>
		</view>
		
		<view class="footer">
			<button class="btn btn_share" @click="onCopyClick">
				<text class="b">复制文案</text>
			</button>
			
			<button class="btn btn_buy" open-type="share">
				<text class="b">分享好友</text>
			</button>
		</view>
	</view>
</template>

<script>
	import { runGetV6Data } from '@/module/api'
	import { encodeGoodId } from '@/common/util'
    import WxNotificationCenter from '@/libs/WxNotificationCenter/wxnotificationcenter'

	const _ = require("@/libs/underscore/underscore-min.js")._
	
	export default {
		data() {
			return {
				scrollTop: 0,
				statusBarHeight: 0,
				loaded: false,
				id: null,
				type: null,
				gallaty: [],
				title: '',
				itemfee: 0,
				itemfee_final: 0,
				itemfee_coupon: 0,
				commission_gift_card: 0,
				commission_gift_card_share: 0,
				sharePic: '',
				sharePic2: '',
				currentPic: 0,
				data: {}
			};
		},
		
		computed: {
			shareAppMessage () {
				return Object.assign(this.$store.state.shareAppMessage, {
					imageUrl: this.currentPic == 0 ? this.sharePic : this.sharePic2,
					title: this.data ? this.data.title || "" : "",
					path: this.id ? "/pages/index/index?scene=" + encodeURIComponent("id="+this.id+"&type="+this.type+"&v=hgd") : ""
				})
			},
			
			userInfo () {
				return this.$store.state.userInfo
			}
		},
		
		onShareAppMessage () {
			return this.shareAppMessage
		},
		
		onPageScroll(e){
			this.scrollTop = e.scrollTop
		},
		
		onReady () {
			let _t = this
			uni.getSystemInfo({
				success: res => {
					// console.log(res)
					_t.statusBarHeight = res.statusBarHeight
				}
			})
		},
		
		onLoad(params) {
			this.id = params.id
			this.type = params.type
			console.log(encodeURIComponent("/pages/home/good-detail/good-detail?id=" + this.id + "&type=" + this.type))
			this.onPageRefresh()
		},
		
		methods:{
			onCopyClick () {
				uni.setClipboardData({
					data: this.title,
					success: () => {
						uni.showToast({
							icon: "none",
							title: "复制成功"
						})
					}
				})
			},
			
			onPhotosSelectClick (index) {
				this.currentPic = index
			},
			
			onPhotosClick (index) {
				uni.previewImage({
					current: index,
					urls: [
						this.sharePic,
						this.sharePic2
					]
				})
			},
			
			onPageRefresh () {
				let _t = this;
				let platform = '';
				switch (this.type) {
					case "3" :
						platform = 'jd'; break;
					case "1" :
						platform = 'tb'; break;
					case "2" :
						platform = 'tb'; break;
					case "4" :
						platform = 'pdd'; break;
				}
				
				runGetV6Data({
					platform,
					params: {
						act: 'share',
						platfrom_type: 'wx_mini',
						itemid: this.id,
						uid: this.userInfo.id
					},
					success: res => {
						let codeStr = '- - -$￥' + encodeGoodId(_t.id.toString() + _t.type.toString()) + '￥$- - -';
						let copyText = ''
		
						if(res.data.itemfee_coupon.toString() == "0"){
							copyText = res.data.title+'\n￥'+res.data.itemfee_final+'\n'+codeStr+'\n 领取下单 '+res.data.change_link+' \n 然后打开链接 即可领取优惠券'
						}else{
							copyText = res.data.title+'\n【原价】￥'+res.data.itemfee+'\n【券后价】￥'+res.data.itemfee_final+'\n'+codeStr+'\n 领取下单 '+res.data.change_link+' \n 然后打开链接 即可领取优惠券'
						}
						
						_t.sharePic = res.data.sharePic
						_t.sharePic2 = res.data.main_pic
						_t.title = copyText
						_t.type = res.data.item_type
						_t.itemfee = res.data.itemfee
						_t.itemfee_final = res.data.itemfee_final
						_t.itemfee_coupon = parseFloat(res.data.itemfee_coupon)
						_t.commission_gift_card = res.data.commission_gift_card || 0
						_t.commission_gift_card_share = res.data.commission_gift_card_share || 0
						_t.data = res.data
						_t.loaded = true
					},
					fail: res => {
						
					},
					error: () => {
						
					}
				})
			}
		}
	}
</script>

<style>
	page{
		background: #F2F2F2;
	}
</style>

<style lang="less">
	.container{
		padding-bottom: 130px;
	}
	
	.h1{
		position: relative;
		padding: 30px;
		background: #FFFFFF;
		
		text{
			width: 100%;
			font-size: 30px;
			color: #333;
		}
			
		.icon{
			position: absolute;
			top: 34px;
			left: 30px;
			width: 40px;
		}
	}
	
	.row{
		padding: 30px 30px 0;
		display: flex;
		justify-content: space-between;
		align-items: center;
		background: #FFFFFF;
		
		&.pt20{
			padding-top: 20px;
		}
		
		&.bdt{
			border-top: 1px solid #eee;
		}
		
		&.mt30{
			margin-top: 30px;
		}
	}
	
	.levelup{
		width: 100%;
		height: 80px;
		padding: 0 20px;
		box-sizing: border-box;
		display: flex;
		justify-content: space-between;
		align-items: center;
		background-color: #333333;
		border-radius: 8px;
		
		text{
			font-size: 26px;
			color: #F9C694;
		}
		
		.go{
			width: 152px;
			height: 60px;
			background: #E7BB90;
			border-radius: 30px;
			font-size: 26px;
			color: #333;
			display: flex;
			justify-content: center;
			align-items: center;
		}
	}
	
	.tips{
		padding: 0px 30px;
		line-height: 80px;
		font-size: 28px;
		color: #333333;
	}
	
	.photos{
		padding: 0px 30px;
		display: flex;
		justify-content: space-between;
		
		.item{
			width: 48%;
			position: relative;
			
			.pic{
				width: 100%;
				border-radius: 8px;
			}
			
			.btn{
				position: absolute;
				width: 40px;
				height: 40px;
				background: rgba(0,0,0,.5);
				border-radius: 40px;
				right: 10px;
				top: 10px;
				display: flex;
				justify-content: center;
				align-items: center;
				
				.icon{
					width: 100%;
					height: 100%;
				}
			}
		}
	}
	
	.footer{
		position: fixed;
		bottom: 0;
		width: 100%;
		left: 0;
		height: 100px;
		background: #FFFFFF;
		z-index: 10;
		box-shadow: 0px -4px 16px 0px rgba(122,142,216,0.27);
		display: flex;
		align-items: center;
		justify-content: center;
		
		.btn{
			width: 50%;
			height: 100%;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			border-radius: 0;
			line-height: 1.25;
			
			text{
				color: #FFFFFF;
				font-size: 24px;
			}
			
			.b{
				font-size: 32px;
			}
		}
		
		.btn_buy{
			background:linear-gradient(270deg,rgba(255,92,120,1) 0%,rgba(231,38,31,1) 100%);
		}
		
		.btn_share{
			background: #333333;
		}
	}
</style>
